
//******************************************************************************
//***************************** Final Dataset *******************************
//******************************************************************************

clear

cd "~/Desktop"

use m_inpt_mini_08to17, clear

append using "FL_inpt_mini_08to17.dta"

// Don't allow double counting - c_section, vagProc, vagNoProc
replace vagProc=0 if vagProc==1 & c_section==1
replace vagNoProc=0 if vagNoProc==1 & c_section==1
replace vagNoProc=0 if vagNoProc==1 & vagProc==1

// Don't allow double counting - c_section
replace code72=0 if code72==1 & c_section==1
replace drugInduce=0 if drugInduce==1 & c_section==1
replace otherObProc=0 if otherObProc==1 & c_section==1

// Don't allow double counting - forceps or vacuum (code72) and otherObProc
replace otherObProc=0 if otherObProc==1 & code72==1

// Don't allow double counting - drugInduce and otherObProc
replace otherObProc=0 if otherObProc==1 & drugInduce==1

gen 	treat = . 
replace treat = 1 if state=="NC"
replace treat = 0 if state=="FL"

save "~/Desktop/NC_and_FL_inpt_mini_08to17", replace

//==============================================================================
//========================== NC and FL Graphs ==================================
//==============================================================================

****************************** Basic descriptives*******************************

****** Malpractice cases over time

//Raw counts

clear

use mal_cases_08to17, clear

gen state="NC"

append using "FL_mal_cases_08to17.dta"

// Case volumes NC: before 89.5 average | after declines to 66 - approximately 27% decrease
// Case volumes FL: before 776.5 average

gen NC_tot_cases = tot_cases if state=="NC"
gen NC_2011_cases = 91 if state=="NC"             // Cases count in NC in 2011
gen NC_prop_cases = NC_tot_cases / NC_2011_cases

gen NC_1 = NC_prop_cases if FisYear<=2011
gen NC_2 = NC_prop_cases if FisYear >=2012

gen FL_tot_cases = tot_cases if state=="FL"
gen FL_2011_cases = 789 if state=="FL"             // Cases count in FL in 2011
gen FL_prop_cases = FL_tot_cases / FL_2011_cases

gen FL_1 = FL_prop_cases if FisYear<=2011
gen FL_2 = FL_prop_cases if FisYear >=2012

set scheme s1mono

sort state FisYear

twoway (connected FL_1 FL_2 NC_1 NC_2 FisYear, lpattern(dash dash solid solid) lcolor(gray gray black black) lwidth(*1.75 *1.75 *1.75 *1.75) msymbol(triangle triangle circle circle) color(gray gray black black)), ///
xlabel(2008(1)2017) ///
ylabel(0(.2)1) ///
ytitle("Statewide Malpractice Case Volumes" "Indexed to 2011") xtitle("Fiscal Year") ///
legend(order(1 "Florida"  3 "North Carolina")) ///
xline(2011.5, lpattern(dash) lwidth(*1.75) lcolor(red)) ///
xsize(5.0) ysize(3.0) scale(1.0)

graph export "~/Documents/Research/output/Malpractice/Figure1.pdf" , replace

****** Births Over Time (normalized)

//Fix FL data

clear

cd "~/Documents/Research/data/other"

import excel "~/Documents/Research/data/other/FLPOP.xls", sheet("FRED Graph") cellrange(A11:B132) firstrow allstring

gen long FL_pop = real(FLPOP)

gen yearString = substr(observation_date, 6, 4)

gen long year = real(yearString)

keep year FL_pop
keep if year>=2008
keep if year<=2017

save "~/Documents/Research/data/other/FLPOP_clean", replace

//Fix NC data

clear

cd "~/Documents/Research/data/other"

import excel "~/Documents/Research/data/other/NCPOP.xls", sheet("FRED Graph") cellrange(A11:B132) firstrow allstring

gen long NC_pop = real(NCPOP)

gen yearString = substr(observation_date, 6, 4)

gen long year = real(yearString)

keep year NC_pop
keep if year>=2008
keep if year<=2017

save "~/Documents/Research/data/other/NCPOP_clean", replace

//Make graph

clear

cd "~/Desktop/"

use NC_and_FL_inpt_mini_08to17, clear

merge m:1 year using "~/Documents/Research/data/other/NCPOP_clean.dta"

drop _merge

merge m:1 year using "~/Documents/Research/data/other/FLPOP_clean.dta"

// Adjust since data is in thousands 
replace FL_pop = FL_pop*1000

// Adjust since data is in thousands 
replace NC_pop = NC_pop*1000

keep if allDeliv==1

sort year state
by year state: gen totalBirths=_N

keep year state totalBirths NC_pop FL_pop

gen NC_birthPerCapita=.
replace NC_birthPerCapita=(totalBirths/NC_pop)*1000 if state=="NC"

gen FL_birthPerCapita=.
replace FL_birthPerCapita=(totalBirths/FL_pop)*1000 if state=="FL"

keep year state NC_birthPerCapita FL_birthPerCapita

duplicates drop

list

twoway (line FL_birthPerCapita NC_birthPerCapita year, lpattern(dash solid) lcolor(gray black) lwidth(*1.75 *1.75)) , ///
xlabel(2008(1)2017) ///
ylabel(0(5)15) ///
ytitle("Hospital-Based Births Per Capita") xtitle("Fiscal Year") ///
legend(order(1 "Florida"  2 "North Carolina")) ///
xline(2011.5, lpattern(dash) lwidth(*1.75) lcolor(red)) ///
xsize(5.0) ysize(3.0) scale(1.0)
	
graph export "~/Documents/Research/output/Malpractice/Figure2.pdf", replace

******* C-section Event Study - with hospital fixed effects

clear

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1

keep facility_id year private medicaid otherIns agey white c_section treat

#delimit ;
global labelcoef "
	c1="2008"
	c2="2009"
	c3="2010"
	c4="2011"
	c5="2012"
	c6="2013"						
	c7="2014"
	c8="2015"	
	c9="2016"
	c10="2017"
";
#delimit cr		

//With FE
areg c_section i.treat##ib2011.year 	      , absorb(facility_id) cluster(facility_id)

matrix list e(b)				// relevant coeffs 23-32 //

matrix V = e(V)
matrix b = e(b)
	
	
	matrix C = J(3,10,.)
	foreach n of num 1(1)10 {
		local x = `n'+22 
		matrix C[1,`n']= b[1,`x']
		matrix C[2,`n']= b[1,`x']-1.96*sqrt(V[`x',`x'])
		matrix C[3,`n']= b[1,`x']+1.96*sqrt(V[`x',`x'])
	}
	set scheme s1mono
	coefplot matrix(C[1]), ci((C[2] C[3])) vertical  base ///
		coeflabels( $labelcoef) xlabel(,angle(45)) xline(4.5, lcolor(red) lpattern(dash_dot))   ///
		msymbol(d) msize(large) ///
		yline(0, lcolor(black) lwidth(thin) lpattern(dash)) graphregion(fcolor(white))  ///
		title( ) ciopts(recast(rspike)) ytitle("Malpractice Reform Effect on Pr(C-section)") xtitle("Fiscal Years") 


graph export "~/Documents/Research/output/Malpractice/Figure3.pdf" , replace


****** Share of inpt delivery visits with a c-section  - Normalized to 1

clear

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1

collapse (mean) c_section, by(state year)

list

drop if year==.

gen NC_2011_prop = .3365115 if state=="NC"
gen NC_prop = c_section / NC_2011_prop

gen FL_2011_prop = .4032522 if state=="FL"
gen FL_prop = c_section / FL_2011_prop

set scheme s1mono

twoway (line FL_prop NC_prop year , lpattern(dash solid) lcolor(gray black) lwidth(*1.75 *1.75)) , ///
xlabel(2008(1)2017) ///
ytitle("Share of Inpt Deliveries with a C-Section"  "Relative to 2011") xtitle("Fiscal Year") ///
legend(order(1 "Florida"  2 "North Carolina")) ///
xline(2011.5, lpattern(dash) lwidth(*1.75) lcolor(red)) ///
xsize(5.0) ysize(3.0) scale(1.0)

graph export "~/Documents/Research/output/Malpractice/AppendixFig1.pdf" , replace


******* Code 72 OB Proc Event Study

clear

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1

keep facility_id year private medicaid otherIns agey white code72 treat

#delimit ;
global labelcoef "
	c1="2008"
	c2="2009"
	c3="2010"
	c4="2011"
	c5="2012"
	c6="2013"						
	c7="2014"
	c8="2015"	
	c9="2016"
	c10="2017"
";
#delimit cr		

//With FE
areg code72 i.treat##ib2011.year 			, absorb(facility_id) cluster(facility_id)	

matrix list e(b)				// relevant coeffs 23-32 //

matrix V = e(V)
matrix b = e(b)
	
	
	matrix C = J(3,10,.)
	foreach n of num 1(1)10 {
		local x = `n'+22 
		matrix C[1,`n']= b[1,`x']
		matrix C[2,`n']= b[1,`x']-1.96*sqrt(V[`x',`x'])
		matrix C[3,`n']= b[1,`x']+1.96*sqrt(V[`x',`x'])
	}
	set scheme s1mono
	coefplot matrix(C[1]), ci((C[2] C[3])) vertical  base ///
		coeflabels( $labelcoef) xlabel(,angle(45)) xline(4.5, lcolor(red) lpattern(dash_dot))   ///
		msymbol(d) msize(large) ///
		yline(0, lcolor(black) lwidth(thin) lpattern(dash)) graphregion(fcolor(white))  ///
		title( ) ciopts(recast(rspike)) ytitle("Malpractice Reform Effect on" "Pr(Forceps or Vacuum)") xtitle("Fiscal Years") 

graph export "~/Documents/Research/output/Malpractice/AppendixFig2.pdf" , replace

******* Medical Induction Event Study

clear

use NC_and_FL_inpt_mini_08to17, clear

keep if allDeliv==1

keep facility_id year private medicaid otherIns agey white drugInduce treat

#delimit ;
global labelcoef "
	c1="2008"
	c2="2009"
	c3="2010"
	c4="2011"
	c5="2012"
	c6="2013"						
	c7="2014"
	c8="2015"	
	c9="2016"
	c10="2017"
";
#delimit cr		

//With FE
areg drugInduce i.treat##ib2011.year 			, absorb(facility_id) cluster(facility_id)	

matrix list e(b)				// relevant coeffs 23-32 //

matrix V = e(V)
matrix b = e(b)
	
	
	matrix C = J(3,10,.)
	foreach n of num 1(1)10 {
		local x = `n'+22 
		matrix C[1,`n']= b[1,`x']
		matrix C[2,`n']= b[1,`x']-1.96*sqrt(V[`x',`x'])
		matrix C[3,`n']= b[1,`x']+1.96*sqrt(V[`x',`x'])
	}
	set scheme s1mono
	coefplot matrix(C[1]), ci((C[2] C[3])) vertical  base ///
		coeflabels( $labelcoef) xlabel(,angle(45)) xline(4.5, lcolor(red) lpattern(dash_dot))   ///
		msymbol(d) msize(large) ///
		yline(0, lcolor(black) lwidth(thin) lpattern(dash)) graphregion(fcolor(white))  ///
		title( ) ciopts(recast(rspike)) ytitle("Malpractice Reform Effect on" "Pr(Medical Labor Induction)") xtitle("Fiscal Years") 

graph export "~/Documents/Research/output/Malpractice/AppendixFig3.pdf" , replace


